<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑管理员</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<form class="layui-form" style="width: 80%;" id="aaf">

    <input type="hidden" name="id" th:value="${admin.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-block">
            <input type="text" id="username" class="layui-input"
                   lay-verify="required" placeholder="请输入登陆名" name="username" th:value="${admin.username}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="fullname" class="layui-input"
                   lay-verify="required" placeholder="请输入姓名" th:value="${admin.fullname}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" id="email" name="email" class="layui-input"
                   lay-verify="email" placeholder="请输入邮箱" th:value="${admin.email}">
            <label>（<span style="color: red">*</span>找回密码必须！）</label>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" th:checked="${admin.sex == '1'}">
            <input type="radio" name="sex" value="0" title="女"  th:checked="${admin.sex == '0'}">
            <input type="radio" name="sex" value="2" title="保密"  th:checked="${admin.sex == '2'}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">出生日期</label>
        <div class="layui-input-block">
            <input type="text" id="birthday" class="layui-input"
                   name="birthday" lay-verify="required"
                   th:value="${#dates.format(admin.birthday,'yyyy-MM-dd')}" autocomplete="off" placeholder="请输入出生日期">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" class="layui-input" lay-verify="required"
                   placeholder="请输入地址" th:value="${admin.address}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" class="layui-input"
                   lay-verify="phone" placeholder="请输入手机号" th:value="${admin.phone}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分配角色</label>
        <div class="layui-input-block">
            <select name="roleId">
                <option value="">请选择</option>
                <option th:each="r:${roles}" th:value="${r.roleId}" th:selected="${r.roleId==admin.roleId}">[[${r.roleName}]]</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="editAdmin">立即提交</button>
        </div>
    </div>
</form>
<script th:src="@{/src/layui.js}"></script>

<script>
        layui.use(['form','jquery','layer','laydate'],function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer,
            laydate = layui.laydate;

            laydate.render({
                elem:'#birthday',
                max:'new Date()',
                trigger:'click'
            });

            //参数data就是表单中的数据
            form.on('submit(editAdmin)',function (data) {
                //data.field;//当前容器的全部表单字段，名值对形式：{name: value}
                $.ajax({
                    url:'/admin/updateAdmin',
                    type:'put',
                    dataType:'json',
                    data:data.field,
                    success:function (result) {
                        if(result.code == 200){
                            layer.msg('更新成功',{icon:1},function () {
                                top.layer.closeAll("iframe");
                                parent.location.reload();
                            })
                        }else{
                            layer.msg(result.message);
                        }
                    }
                });

                return false;
            })

        });

</script>
</body>
</html>